using System;
using System.Reflection;
using UnityEngine;

namespace CinemaDirector
{
	[Serializable]
	public class MemberClipCurveData
	{
		public string Type;

		public string PropertyName;

		public bool IsProperty = true;

		public PropertyTypeInfo PropertyType = PropertyTypeInfo.None;

		public AnimationCurve Curve1 = new AnimationCurve();

		public AnimationCurve Curve2 = new AnimationCurve();

		public AnimationCurve Curve3 = new AnimationCurve();

		public AnimationCurve Curve4 = new AnimationCurve();

		private object cachedProperty;

		public AnimationCurve GetCurve(int i)
		{
			switch (i)
			{
			case 1:
				return Curve2;
			case 2:
				return Curve3;
			case 3:
				return Curve4;
			default:
				return Curve1;
			}
		}

		public void Initialize(GameObject Actor)
		{
			Component component = Actor.GetComponent(Type);
			cachedProperty = getCurrentValue(component);
		}

		internal void Reset(GameObject Actor)
		{
			Component component = Actor.GetComponent(Type);
			if (!(component == null) && !(PropertyName == string.Empty))
			{
				Type type = component.GetType();
				if (IsProperty)
				{
					PropertyInfo property = type.GetProperty(PropertyName);
					property.SetValue(component, cachedProperty, null);
				}
				else
				{
					FieldInfo field = type.GetField(PropertyName);
					field.SetValue(component, cachedProperty);
				}
			}
		}

		private object getCurrentValue(Component component)
		{
			if (component == null || PropertyName == string.Empty)
			{
				return null;
			}
			Type type = component.GetType();
			object obj = null;
			if (IsProperty)
			{
				PropertyInfo property = type.GetProperty(PropertyName);
				return property.GetValue(component, null);
			}
			FieldInfo field = type.GetField(PropertyName);
			return field.GetValue(component);
		}
	}
}
